package cs131.pa1.filter.sequential;

import java.io.File;
import java.util.List;

public class LsCommand extends SequentialFilter{

    public final static String COMMAND = "ls";

    private String option = "";
    private List<String> commands;

    public LsCommand(List<String> commands) {
        this.commands=commands;
    }

    public void process(){
        if (isInterruption()){
            return;
        }
		listFilesAndFilesSubDirectories(SequentialREPL.currentWorkingDirectory);
	}
	
	public void listFilesAndFilesSubDirectories(String dn){
	    if("-a".equals(option)){
            output.add(".");
            output.add("..");
        }else if(!"".equals(option)){
            output.add(cs131.pa1.filter.Message.REQUIRES_PARAMETER.with_parameter(COMMAND));
            return;
        }
        File directory = new File(dn);
        File[] fList = directory.listFiles();
        for (File file : fList){
            printFile(file);
        }
    }

    private void printFile(File file){
	    if("-a".equals(option) || !file.isHidden()){
	        if(next==null){
                System.out.println(file.getName());
            }else {
                output.add(file.getName());
            }
        }
    }
	@Override
	protected String processLine(String line) {
		return null;
	}
	
}
 